﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJ.Business.SalePurchase;
using System.Windows;
using PJ.Business;
using Microsoft.Practices.Composite.Events;

namespace PJ.Presentation.SalePurchase
{
    public abstract class ShoppingCartItemModel : EntityFragmentViewModel
    {
        public ShoppingCartItemModel(IView view, IEventAggregator aggregator, IShoppingCartItemService service)
            : base(view, aggregator, service)
        {
        }

        /// <summary>
        /// GetValues. Sets the businness object properties using the model property values
        /// </summary>
        /// <param name="businessObject">business object to update</param>
        public override IBusinessObject GetValues(IBusinessObject businessObject)
        {
            base.GetValues(businessObject);
            IShoppingCartItem val = (IShoppingCartItem)businessObject;
            val.Order = Order;
            val.InventoryItemID = InventoryItemID;
            val.Quantity = Quantity;
            val.UnitID = UnitID;            
            return businessObject;
        }
        /// <summary>
        /// SetValues. Sets the model properties using the businessobject property values
        /// </summary>
        /// <param name="businessObject"></param>
        public override void SetValues(IBusinessObject businessObject)
        {
            base.SetValues(businessObject);
            IShoppingCartItem val = (IShoppingCartItem)businessObject;
            Order = val.Order;            
            InventoryItemID = val.InventoryItemID;
            Quantity = val.Quantity;
            UnitID = val.UnitID;
        }

        public double Order
        {
            get { return (double)ThreadUnsafeGetValue(OrderProperty); }
            set { ThreadUnsafeSetValue(OrderProperty, value); }
        }

        public static readonly DependencyProperty OrderProperty =
            DependencyProperty.Register("Order", typeof(double), typeof(ShoppingCartItemModel), new UIPropertyMetadata(0.0));

        public string InventoryItemID
        {
            get { return (string)ThreadUnsafeGetValue(InventoryItemIDProperty); }
            set { ThreadUnsafeSetValue(InventoryItemIDProperty, value); }
        }

        public static readonly DependencyProperty InventoryItemIDProperty =
            DependencyProperty.Register("InventoryItemID", typeof(string), typeof(ShoppingCartItemModel), new UIPropertyMetadata(""));

        public double Quantity
        {
            get { return (double)ThreadUnsafeGetValue(QuantityProperty); }
            set { ThreadUnsafeSetValue(QuantityProperty, value); }
        }

        public static readonly DependencyProperty QuantityProperty =
            DependencyProperty.Register("Quantity", typeof(double), typeof(ShoppingCartItemModel), new UIPropertyMetadata(1.0));

        public string UnitID
        {
            get { return (string)ThreadUnsafeGetValue(UnitIDProperty); }
            set { ThreadUnsafeSetValue(UnitIDProperty, value); }
        }

        public static readonly DependencyProperty UnitIDProperty =
            DependencyProperty.Register("UnitID", typeof(string), typeof(ShoppingCartItemModel), new UIPropertyMetadata(""));

    }
}
